# -*- coding:utf-8 -*-

__author__='zhaoxp'

'''
Python提供两种时间转换方法，旧的是time模块，极易出错，新的是datetime模块。
'''

import time
import datetime


def time_usage():
    now = 1407694710
    print('now = %s'%now)
    local_tuple = time.localtime(now)
    #local_tuple = time.localtime()
    time_format = '%Y-%m-%d %H:%M:%S'
    time_str = time.strftime(time_format,local_tuple)
    print('time_str = %s'%time_str)
    print('')
    
    print('analyze time string')
    time_tuple2 = time.strptime(time_str,time_format)
    utc_now = time.mktime(local_tuple)
    print('utc_now = %s'%utc_now)
    print('')
    '''
    parse_format = '%Y-%m-%d %H:%M:%S %Z'
    depart_sfo = '2014-05-01 15:45:16 +8'
    time_tuple = time.strptime(depart_sfo,parse_format)
    time_str = time.strftime(time_format,time_tuple)
    print('time_str = %s'%time_str)
    '''


def datetime_usage():
    now = datetime.datetime(2014, 8, 10, 18 ,18 ,30)
    print('now = %s'%now)
    now_utc = now.replace(tzinfo=datetime.timezone.utc)
    now_local = now_utc.astimezone()
    print('now_local = %s'%now_local)


if __name__=='__main__':
    print('Make pickle reliable with copyreg')
    time_usage()
    print('*'*40)
    datetime_usage()
